<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="客户名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入客户名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="联系人" prop="contact">-->
<!--        <el-input-->
<!--          v-model="queryParams.contact"-->
<!--          placeholder="请输入商务联系人"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="联系电话" prop="contactno">-->
<!--        <el-input-->
<!--          v-model="queryParams.contactno"-->
<!--          placeholder="请输入商务联系电话"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="省份" prop="province">-->
<!--        <el-input-->
<!--          v-model="queryParams.province"-->
<!--          placeholder="请输入省份"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="城市" prop="city">-->
<!--        <el-input-->
<!--          v-model="queryParams.city"-->
<!--          placeholder="请输入城市"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="客户类型" prop="status">
        <el-select size="small" v-model="queryParams.type" placeholder="请选择客户类型" clearable>
            <el-option
              v-for="dict in typeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
      </el-form-item>
      <el-form-item label="应收客户" prop="recbalanceFlag">
        <el-select size="small" v-model="queryParams.recbalanceFlag" placeholder="请选择是否是应收客户" clearable>
          <el-option label="是" value="1"/>
          <el-option label="否" value="0"/>
        </el-select>
      </el-form-item>
      <el-form-item label="预收客户" prop="flagPrebalance">
        <el-select size="small" v-model="queryParams.flagPrebalance" placeholder="请选择是否是预收客户" clearable>
            <el-option
              v-for="dict in flagPrebalanceOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
      </el-form-item>
      <el-form-item label="金蝶编码" prop="kingdeenum">
        <el-input v-model="queryParams.kingdeenum" placeholder="请输入金蝶编码" size="small" clearable/>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['customer:customer:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['customer:customer:edit']"
        >修改</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['customer:customer:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['customer:customer:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="customerList" @selection-change="handleSelectionChange" :show-summary="true" sum-text="合计(所有页)" :summary-method="sumIt">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="客户名称" align="center" prop="name" width="240" >
        <template slot-scope="scope">
          <span @click="handleView(scope.row)" style="color: #1890ff;cursor: pointer;">{{ scope.row.name }}</span>
<!--          <span>{{ scope.row.name }}</span>-->
        </template>
      </el-table-column>
      <el-table-column label="联系人" align="center" prop="contact" width="60" />
      <el-table-column label="联系电话" align="center" prop="contactno" />
<!--      <el-table-column label="地址" align="center" width="150">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ scope.row.province + '' + scope.row.city + '' + scope.row.district + '' + scope.row.address }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!-- <el-table-column label="财务联系人" align="center" prop="financer" />
<el-table-column label="财务联系人电话" align="center" prop="fintel" /> -->
      <el-table-column label="初始应收余额" align="center" prop="recbalanceManual"/>
      <el-table-column label="应收订单余额" align="center" prop="">
        <template slot-scope="scope">
          <span @click="recbalanceInfo(scope.row)" style="color: #00afff;cursor: pointer">{{scope.row.recbalance}}</span>
        </template>
      </el-table-column>
      <el-table-column label="应收款余额" align="center" prop="recbalanceZK"/>
      <el-table-column label="预收款余额" align="center" prop="prebalance" />
<!--      <el-table-column label="应收账款" align="center" prop="recbalance" />-->
<!--      <el-table-column label="货币预付款余额" align="center" prop="currprebalance" />-->
<!--      <el-table-column label="非货币预付款余额" align="center" prop="nocurrprebalance" />-->
      <el-table-column label="金蝶编号" align="center" prop="kingdeenum" width="80" />
      <el-table-column label="状态" align="center" prop="statusname" width="60" />
      <!-- <el-table-column label="同步日期" align="center" prop="synchtime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.synchtime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="同步信息" align="center" prop="synchinfo" />
      <el-table-column label="同步状态" align="center" prop="synchstat" :formatter="synchstatFormat" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-info"
            @click="$router.push({path: '/customer/custcashflowinfo', query: {id: scope.row.id}})"
            v-hasPermi="['customer:customer:prebalancedetail']"
          >查看预收款</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['customer:customer:edit']"
          >修改</el-button>
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['customer:customer:remove']"-->
<!--          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改客户管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1100px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" :inline="true" label-width="120px">
        <el-form-item label="客户名称" prop="name">
          <el-input v-model="form.name" clearable  placeholder="请输入客户名称" />
        </el-form-item>
        <el-form-item label="客户类型" prop="type">
          <el-select v-model="form.type" clearable  placeholder="请选择客户类型">
            <el-option
              v-for="dict in typeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
              @click.native="getType($event, dict)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" clearable  placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="关联组织" prop="orgguid" v-if="orgShow">
          <el-select v-model="form.orgguid" clearable  placeholder="请选择组织" filterable clearable size="small">
            <el-option
              v-for="item in orgOptions"
              :key="item.guid"
              :label="item.name"
              :value="item.guid"
            />
        </el-select>
        </el-form-item>
        <el-form-item label="地址" prop="province">
          <v-distpicker :province="form.province" :city="form.city" :area="form.district" @selected="onSelected"></v-distpicker>
        </el-form-item>
        <!-- <el-form-item label="市" prop="city">
          <el-input v-model="form.city" clearable  placeholder="请输入市" />
        </el-form-item>
        <el-form-item label="区县" prop="district">
          <el-input v-model="form.district" clearable  placeholder="请输入区县" />
        </el-form-item> -->
        <el-form-item label="详细地址" prop="address">
          <el-input v-model="form.address" clearable  placeholder="请输入地址" />
        </el-form-item>
        <el-form-item label="商务联系人" prop="manager">
          <el-input v-model="form.manager" clearable  placeholder="请输入商务联系人" />
        </el-form-item>
        <el-form-item label="商务联系电话" prop="managertel">
          <el-input v-model="form.managertel" clearable  placeholder="请输入商务联系电话" />
        </el-form-item>
        <el-form-item label="联系人" prop="contact">
          <el-input v-model="form.contact" clearable  placeholder="请输入联系人" />
        </el-form-item>
        <el-form-item label="联系电话" prop="contactno">
          <el-input v-model="form.contactno" clearable  placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="法人" prop="legal">
          <el-input v-model="form.legal" clearable  placeholder="请输入法人" />
        </el-form-item>
        <el-form-item label="联系人邮箱" prop="memail">
          <el-input v-model="form.memail" clearable  placeholder="请输入联系人邮箱" />
        </el-form-item>
        <el-form-item label="财务联系人" prop="financer">
          <el-input v-model="form.financer" clearable  placeholder="请输入财务联系人" />
        </el-form-item>
        <el-form-item label="财务联系人电话" prop="fintel">
          <el-input v-model="form.fintel" clearable  placeholder="请输入财务联系人电话" />
        </el-form-item>
        <el-form-item label="财务联系人邮箱" prop="finemail">
          <el-input v-model="form.finemail" clearable  placeholder="请输入财务联系人邮箱" />
        </el-form-item>
        <el-form-item label="注册资金" prop="registcapital">
          <el-input v-model="form.registcapital" clearable  placeholder="请输入注册资金" />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select v-model="form.status" clearable  placeholder="请选择状态">
            <el-option
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="应付账款" prop="paybalance">
          <el-input v-model="form.paybalance" clearable  placeholder="请输入应付账款" />
        </el-form-item> -->
        <el-form-item label="结算币种" prop="currency">
          <el-select v-model="form.currency" clearable placeholder="请选择结算币种">
            <el-option
              v-for="dict in currencyOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否电商客户" prop="flag">
          <el-select v-model="form.flag" clearable  placeholder="请选择是否电商客户">
            <el-option
              v-for="dict in flagOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="金蝶编号" prop="kingdeenum">
          <el-input v-model="form.kingdeenum" clearable placeholder="请输入金蝶编号" />
        </el-form-item>
        <el-form-item label="是否折扣" prop="isdiscount">
          <el-select v-model="form.isdiscount" clearable  placeholder="请选择是否有折扣">
            <el-option
              v-for="dict in isdiscount"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
              @click.native="getType($event, dict)"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 详情对话框 -->
    <el-dialog :title="title" :visible.sync="open3" width="1100px" append-to-body>
      <el-form ref="form" class="modalform" :inline="true" label-width="120px">
        <el-form-item label="客户名称" prop="name">
          <el-input :value="form.name" readonly />
        </el-form-item>
        <el-form-item label="客户类型" prop="cusCtractId">
          <el-input :value="typeFormat(form)" readonly />
        </el-form-item>
        <el-form-item label="关联组织" prop="cusCtractId">
          <el-input :value="form.orgname" readonly />
        </el-form-item>
        <el-form-item label="地址" prop="cusCtractId">
          <el-input :value="form.province + form.city + form.district + form.address" readonly />
        </el-form-item>
        <el-form-item label="商务联系人" prop="cusCtractId">
          <el-input :value="form.manager" readonly />
        </el-form-item>
        <el-form-item label="商务联系电话" prop="cusCtractId">
          <el-input :value="form.managertel" readonly />
        </el-form-item>
        <el-form-item label="联系人" prop="cusCtractId">
          <el-input :value="form.contact" readonly />
        </el-form-item>
        <el-form-item label="联系电话" prop="cusCtractId">
          <el-input :value="form.contactno" readonly />
        </el-form-item>
        <el-form-item label="联系人邮箱" prop="cusCtractId">
          <el-input :value="form.memail" readonly />
        </el-form-item>
        <el-form-item label="财务联系人" prop="cusCtractId">
          <el-input :value="form.financer" readonly />
        </el-form-item>
        <el-form-item label="财务联系人电话" prop="cusCtractId">
          <el-input :value="form.fintel" readonly />
        </el-form-item>
        <el-form-item label="财务联系人邮箱" prop="cusCtractId">
          <el-input :value="form.finemail" readonly />
        </el-form-item>
        <el-form-item label="法人" prop="cusCtractId">
          <el-input :value="form.legal" readonly />
        </el-form-item>
        <el-form-item label="注册资金" prop="cusCtractId">
          <el-input :value="form.registcapital" readonly />
        </el-form-item>
        <el-form-item label="状态" prop="cusCtractId">
          <el-input :value="form.statusname" readonly />
        </el-form-item>
        <el-form-item label="应付账款" prop="cusCtractId">
          <el-input :value="attachUnit(form.paybalance, '元')" readonly />
        </el-form-item>
        <el-form-item label="结算币种" prop="cusCtractId">
          <el-input :value="currencyFormat(form)" readonly />
        </el-form-item>
        <el-form-item label="是否电商客户" prop="cusCtractId">
          <el-input :value="flagFormat(form)" readonly />
        </el-form-item>
        <el-form-item label="金蝶编号" prop="cusCtractId">
          <el-input :value="form.kingdeenum" readonly />
        </el-form-item>
        <el-form-item label="是否折扣" prop="cusCtractId">
          <el-input :value="discountFormat(form)" readonly />
        </el-form-item>
        <el-form-item label="备注" prop="cusCtractId">
          <el-input :value="form.remark" readonly />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <!--        <el-button type="primary" @click="submitForm" :disabled="form.status > 1">确 定</el-button>-->
        <el-button @click="cancel3">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 预收款详情对话框 -->
    <el-dialog :title="title" :visible.sync="open4" width="1100px" append-to-body>
      <el-form ref="form" class="modalform" :inline="true" label-width="120px">
        <div>
          <el-form-item label="客户名称" prop="name">
            <el-input :value="form.name" readonly />
          </el-form-item>
        </div>
        <el-form-item label="预收款余额">
          <el-input :value="attachUnit2(form.prebalance, '元')" readonly />
        </el-form-item>
        <el-form-item label="在途订单金额">
          <el-input :value="attachUnit2(form.prebalanceUsabling, '元')" readonly />
        </el-form-item>
        <el-form-item label="可用余额">
          <el-input :value="attachUnit2(form.prebalanceUsable, '元')" readonly />
        </el-form-item>
      </el-form>
      <p>交易记录：</p>
      <el-table v-loading="loading4" :data="cashflows">
<!--        <el-table-column label="类型" align="center" prop="typename" />-->
        <el-table-column label="编号" align="center" prop="code" />
        <el-table-column label="金额(元)" align="center" prop="amount" />
        <el-table-column label="余额(元)" align="center" prop="prebalance" />
        <el-table-column label="操作人" align="center" prop="operator" />
        <el-table-column label="操作时间" align="center" prop="createtime" />
      </el-table>
      <p>在途订单：</p>
      <el-table v-loading="loading4" :data="orders">
        <el-table-column label="订单编号" align="center" prop="sellcode" />
        <el-table-column label="订单金额(元)" align="center" prop="finalamount" />
        <el-table-column label="状态" align="center" prop="statusname" />
        <el-table-column label="下单人" align="center" prop="applyname" />
        <el-table-column label="下单时间" align="center" prop="createtime" />
      </el-table>
      <div slot="footer" class="dialog-footer">
        <!--        <el-button type="primary" @click="submitForm" :disabled="form.status > 1">确 定</el-button>-->
        <el-button @click="cancel4">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCustomer, getCustomer, delCustomer, addCustomer, updateCustomer, exportCustomer, getSumBalance } from "@/api/customer/customer";
import { findOrganizationList } from "@/api/public";
export default {
  name: "Customer",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      loading4: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 客户管理表格数据
      customerList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 状态字典
      statusOptions: [],
      // 结算币种:1-人民币,2-美元字典
      currencyOptions: [],
      // 客户类型:1-销售客户,2-供应商(种植户)字典
      typeOptions: [],
      // 是否电商客户:1-电商2-普通3-海外字典
      flagOptions: [],
      // 同步状态1-未同步 2-同步成功 3-同步失败字典
      synchstatOptions: [],

      //是否折扣：1-是，2-否
      isdiscount: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        recbalanceFlag:null,
        name: null,
        status: null,
        statusList: [],
        flagPrebalance: '',
        kingdeenum:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [
          { required: true, message: "客户名称不能为空", trigger: "blur" }
        ],
        type: [
          { required: true, message: "客户类型不能为空", trigger: "change" }
        ],
        province: [
          { required: true, message: "地址省市区不能为空", trigger: "change" }
        ],
        address: [
          { required: true, message: "详细地址不能为空", trigger: "blur" }
        ],
        currency: [
          { required: true, message: "结算币种不能为空", trigger: "change" }
        ]
      },
      orgOptions: [],
      orgShow: false,
      open3: false,
      open4: false,
      flagPrebalanceOptions: [
        {dictValue: 1, dictLabel: '是'},
        {dictValue: 0, dictLabel: '否'},
      ],
      cashflows: [],
      orders: [],
      sumBalance: ''
    };
  },
  created() {
    this.getList();
    this.findOrganizationList();
    this.getDicts("cust_status").then(response => {
      this.statusOptions = response.data;
    });
    this.getDicts("currency_type").then(response => {
      this.currencyOptions = response.data;
    });
    this.getDicts("customer_type").then(response => {
      this.typeOptions = response.data;
    });
    this.getDicts("online_customer").then(response => {
      this.flagOptions = response.data;
    });
    this.getDicts("sync_status").then(response => {
      this.synchstatOptions = response.data;
    });
    this.getDicts("isdiscount").then(response => {
      this.isdiscount = response.data;
    });
  },
  methods: {
    recbalanceInfo(row){
      this.$router.push({path:'/customer/recbalanceinfo',query:{id:row.id,guid:row.guid}})
    },
    sumIt(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        // index 第几列从0开始
        if (index === 1) {
          sums[1] = '合计(所有页)';
          return;
        }
        if (index === 4) {
          sums[index] = this.sumBalance;
          return;
        }
        sums[index] = '-';
      });
      return sums;
    },
    cancel3() {
      this.open3 = false;
      this.reset();
    },
    cancel4() {
      this.open4 = false;
      this.reset();
    },
    /** xiangqing按钮操作 */
    handleView(row) {
      this.reset();
      const guid = row.guid || this.ids
      getCustomer(guid).then(response => {
        this.form = response.data;
        this.open3 = true;
        this.title = "客户详情";
      });
    },
    getType(event, item){
      if(item.dictValue == 2){
        this.orgShow = true;
      }else{
        this.orgShow = false;
      }
    },
    //查询组织
    findOrganizationList(){
      findOrganizationList().then(response => {
        this.orgOptions = response.data;
      });
    },

    onSelected(data) {
      this.form.province = data.province.value
      this.form.city = data.city.value
      this.form.district = data.area.value
    },
    /** 查询客户管理列表 */
    getList() {
      if (this.queryParams.recbalanceFlag==0){
        this.queryParams.recbalanceFlag=null;
      }
      if (!this.queryParams.kingdeenum){
        this.queryParams.kingdeenum=null;
      }
      if (!this.queryParams.flagPrebalance){
        this.queryParams.flagPrebalance=null;
      }
      this.loading = true;
      listCustomer(this.queryParams).then(response => {
        this.customerList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
      this.getSumBalance();
    },
    /** 查询余额合计 */
    getSumBalance() {
      let queryParams = JSON.parse(JSON.stringify(this.queryParams));
      Reflect.deleteProperty(queryParams, 'pageSize')
      Reflect.deleteProperty(queryParams, 'pageNum')
      getSumBalance(queryParams).then(response => {
        console.log('response:', response)
        this.sumBalance = response.data;
      });
    },
    // 状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 结算币种:1-人民币,2-美元字典翻译
    currencyFormat(row, column) {
      return this.selectDictLabel(this.currencyOptions, row.currency);
    },
    // 客户类型:1-销售客户,2-供应商(种植户)字典翻译
    typeFormat(row, column) {
      return this.selectDictLabel(this.typeOptions, row.type);
    },
    // 是否电商客户:1-电商2-普通3-海外字典翻译
    flagFormat(row, column) {
      return this.selectDictLabel(this.flagOptions, row.flag);
    },
    // 同步状态1-未同步 2-同步成功 3-同步失败字典翻译
    synchstatFormat(row, column) {
      return this.selectDictLabel(this.synchstatOptions, row.synchstat);
    },
    //是否折扣
    discountFormat(row, column) {
      return this.selectDictLabel(this.isdiscount, row.isdiscount);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        guid: null,
        name: null,
        province: null,
        city: null,
        district: null,
        address: null,
        manager: null,
        managertel: null,
        contact: null,
        contactno: null,
        remark: null,
        operatorid: null,
        createtime: null,
        legal: null,
        memail: null,
        financer: null,
        fintel: null,
        finemail: null,
        registcapital: null,
        prebalance: null,
        recbalance: null,
        status: null,
        operator: null,
        paybalance: null,
        currency: null,
        type: null,
        currprebalance: null,
        nocurrprebalance: null,
        flag: null,
        kingdeenum: null,
        synchtime: null,
        synchinfo: null,
        synchstat: null,
        orgguid: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
          pageSize: 10,
          name: null,
          manager: null,
          managertel: null,
          fintel: null,
          status: null,
          statusList: [],
          province: '',
          city: '',
      },
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.guid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加客户管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const guid = row.guid || this.ids
      getCustomer(guid).then(response => {
        this.form = response.data;
        if(response.data.type == 2){
          this.orgShow = true;
        }else{
          this.orgShow = false;
        }
        this.open = true;
        this.title = "修改客户管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.guid != null) {
            updateCustomer(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCustomer(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const guids = row.guid || this.ids;
      this.$confirm('是否确认删除该数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delCustomer(guids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有客户管理数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportCustomer(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
